package com.margo.project.retry.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;
import org.springframework.stereotype.Component;


/**
 * 	执行顺序
 * 		RetryListener open
 * 		RetryListener onError
 * 		RetryListener close
 * @author fangxingbang
 *
 */
@Component
public class MargoRetryListener implements RetryListener{

	Logger logger=LoggerFactory.getLogger(MargoRetryListener.class);
	
	/**
	 * 	这里要返回true，否则抛出异常  Retry terminated abnormally by interceptor before first attempt
	 */
	@Override
	public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
		logger.info("RetryListener open");
		return true;
	}

	@Override
	public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback,
			Throwable throwable) {
		logger.info("RetryListener close");
		
	}

	@Override
	public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback,
			Throwable throwable) {
		logger.info("RetryListener onError");
	}

}
